﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "NdbObjectSchematic.h"
#include "IExternalObject.h"
#include "ElementCreationOptions.h"
#include "RegenDataSchema.h"
#include "../WallModule.h"
#include "WallData.h"
#include "WallObject.h"
#include "DBUtils.h"

namespace gcmp
{
    class IDocument;
    class IElement;
    class ElementId;
    class IBody;
    class Vector3d;
}

namespace Sample
{
    // 墙体实现类，如果启用USE_SERIALIZE宏，将使用自定义序列化能力
    class WALLMODULE_EXPORT Wall : public gcmp::NdbObjectSchematic, public gcmp::IExternalObject
    {
    private:
        DBOBJECT_DATA_BEGIN(Sample, Wall, gcmp::NdbObjectSchematic, 15CE909B - 3804 - 4BA3 - BE87 - D73DCC92B6FA, WallModule)
            DATA_TRANSIENT(gcmp::IElement*, OwnerElement)
#if USE_SERIALIZE
            DATA(gcmp::OwnerPtr<WallObject>, DbObject)
            DBOBJECT_DATA_END
            DECLARE_REGEN_FUNCTIONS(Data)
#else
            DATA(std::wstring, Name)
            DATA_REGEN(gcmp::OwnerPtr<WallData>, Data)
            DATA_REGEN(gcmp::ElementId, WallTagId)
            DBOBJECT_DATA_END
#endif
    public:
        virtual ~Wall() {};
        gcmp::IDocument* GetDocument() const;

        gcmp::ElementId GetOwnerElementId() const;

    public:
#if USE_SERIALIZE
        virtual void SetDbObject(gcmp::OwnerPtr<WallObject> opObject);
        virtual WallObject* GetDbObject();
#else
        std::wstring GetName() const;
        void SetName(const std::wstring& szName);

        virtual void SetData(gcmp::OwnerPtr<WallData> opData);
#endif
        virtual const WallData* GetData() const;
        virtual WallData* GetData();
        virtual gcmp::ElementId GetWallTagId() const;
        virtual bool SetWallTagId(const gcmp::ElementId& wallTagId);

    public:  //重载IExternalObject
        virtual bool SetOwnerElement(gcmp::IElement* pOwnerElement) override;

        virtual const gcmp::IElement* GetOwnerElement() const override;

        virtual gcmp::IElement* GetOwnerElement() override;

        virtual void UpdateForWeakParentDeletion(const std::set<gcmp::ElementId>& deletedElementIds) override;

        virtual void ReportParents(gcmp::IElementParentReporter& elementParentReporter) const override;

        virtual bool FinishEditing() override;

    public:
        // 墙体创建方法
        static Wall* Create(gcmp::IDocument* pDoc, gcmp::ElementCreationOptions eco = gcmp::ElementCreationOptions::Normal);
        static Wall* Create(gcmp::IDocument* pDoc, const gcmp::Vector3d& startPt, const gcmp::Vector3d& endPt,
            gcmp::ElementCreationOptions eco = gcmp::ElementCreationOptions::Normal);

        // 几何表达创建方法
        gcmp::OwnerPtr<gcmp::IBody> MakeBody();

        //夹点功能依赖
        static gcmp::UniIdentity GetImplementationUid();

        // 由于墙体类不与其它Element进行数据操作，所以GetTopOwnerObject()返回nullptr
        NDB_TOPPARENT_NULL;
    };
}

